package cn.iocoder.yudao.module.student.controller.app.studentFeedback;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
import cn.iocoder.yudao.module.student.controller.app.studentFeedback.vo.StudentFeedbackCreateReqVO;
import cn.iocoder.yudao.module.student.controller.app.studentFeedback.vo.StudentFeedbackPageReqVO;
import cn.iocoder.yudao.module.student.controller.app.studentFeedback.vo.StudentFeedbackRespVO;
import cn.iocoder.yudao.module.student.controller.app.studentFeedback.vo.StudentFeedbackUpdateReqVO;
import cn.iocoder.yudao.module.student.dal.dataobject.studentFeedback.StudentFeedbackDO;
import cn.iocoder.yudao.module.student.service.studentFeedback.StudentFeedbackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Api(tags = "管理后台 - 实践项目反馈")
@RestController
@RequestMapping("/student/feedback")
@Validated
public class StudentFeedbackController {

    @Resource
    private StudentFeedbackService studentFeedbackService;

//    @PostMapping("/create")
//    @ApiOperation("创建实践项目反馈")
//    public CommonResult<Long> createPraxisProjectFeedback(@Valid @RequestBody StudentFeedbackCreateReqVO createReqVO) {
//        return success(studentFeedbackService.createPraxisProjectFeedback(createReqVO));
//    }

    @PutMapping("/update")
    @PreAuthenticated
    @ApiOperation("更新实践项目反馈")
    public CommonResult<Boolean> updatePraxisProjectFeedback(@Valid @RequestBody StudentFeedbackUpdateReqVO updateReqVO) {
        updateReqVO.setFeedbackStatus(1);
        studentFeedbackService.updatePraxisProjectFeedback(updateReqVO);
        return success(true);
    }

//    @DeleteMapping("/delete")
//    @ApiOperation("删除实践项目反馈")
//    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
//    public CommonResult<Boolean> deletePraxisProjectFeedback(@RequestParam("id") Long id) {
//        studentFeedbackService.deletePraxisProjectFeedback(id);
//        return success(true);
//    }

    @GetMapping("/get")
    @ApiOperation("获得实践项目反馈")
    @PreAuthenticated
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
    public CommonResult<StudentFeedbackRespVO> getPraxisProjectFeedback(@RequestParam("id") Long id) {
        StudentFeedbackDO f = studentFeedbackService.getPraxisProjectFeedback(id);
        StudentFeedbackRespVO respVO=new StudentFeedbackRespVO();
        BeanUtils.copyProperties(f,respVO);
        return success( respVO);
    }

    @PostMapping("/page")
    @PreAuthenticated
    @ApiOperation("获得实践项目反馈分页")
    public CommonResult<PageResult<StudentFeedbackRespVO>> getPraxisProjectFeedbackPage(@Valid @RequestBody StudentFeedbackPageReqVO pageVO) {
        PageResult<StudentFeedbackDO> page = studentFeedbackService.getPraxisProjectFeedbackPage(pageVO);
        PageResult<StudentFeedbackRespVO> pageResult=new PageResult<>();
        pageResult.setTotal(page.getTotal());
        List<StudentFeedbackDO> list = page.getList();
        List<StudentFeedbackRespVO> rList=new ArrayList<>();
        if(CollectionUtils.isNotEmpty(list)){
            list.stream().forEach(f->{
                StudentFeedbackRespVO respVO=new StudentFeedbackRespVO();
                BeanUtils.copyProperties(f,respVO);
                rList.add(respVO);
            });
            pageResult.setList(rList);
        }
        return success(pageResult);
    }

}
